﻿@model IEnumerable<LeadMaster.Models.Orders>

<img src="~/Images/create.png" class="addorder navbuttons boxtitle" />
<label class="boxtitle">Orders</label>

<table class="listtable contactstable" cellspacing="0" cellpadding="0">
<thead>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Company.Company)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.OrderStatus)
        </th>
        <th></th>
        <th></th>
    </tr>
</thead>
@foreach (var item in Model) {
    <tr>
        <td>
            <img src="~/Images/Edit.png" class="editorder" id="edit@(item.OrderID)" style="width: 15px; height: 15px; cursor: pointer;" />
            @Html.DisplayFor(modelItem=> item.Company.Company)
        </td>
        <td>
            @Html.DisplayFor(modelItem=> item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.OrderStatus.OrderStatusDescription)
        </td>
        <td>
        <!-- remove toolbar completely by adding &rc:Toolbar=false to the link below -->
        <a href="http://www.dunsmorecrm.co.uk/ReportServer/Pages/ReportViewer.aspx?%2fdunsmore%2fOrder&rs:Command=Render&OrderID=@(item.OrderID)&rc:Parameters=false">
        <img src="../../Images/viewdoc.png" class="view"/>
        </a>
        </td>
        <td>
            @Html.ActionLink("Delete", "Delete", null, new { id = item.OrderID }, new { @class = "delete" })
        </td>
    </tr>
}

</table>

<div id="addorderdialog">
</div>

<div id="editorderdialog">
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $(".editorder").click(function () {
            var id = $(this).attr('id').substring(4);
            $("#editorderdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#editorderdialog').load('@(Url.Action("Edit", "Orders"))/' + id,
        function () {
            $("#editorderdialog").dialog("close");
            $("#editorderdialog").dialog(
            {
                autoOpen: true,
                width: 1200,
                height: 800,
                open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });
        $("#editorderdialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

        $(".addorder").click(function () {
            $("#addorderdialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#addorderdialog').load('@(Url.Action("Create", "Orders"))' ,
        function () {
            $("#addorderdialog").dialog("close");
            $("#addorderdialog").dialog(
            {
                autoOpen: true,
                width: 1200,
                height: 800,
                open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });
        $("#addorderdialog").dialog(
            {
                autoOpen: true,
                width: 200,
                position: { my: 'center', at: 'center', of: window },
                modal: true,
                resizable: false,
                draggable: false,
                dialogClass: 'notitle'
            });
        });

    });
</script>